﻿//页面加载
$(document).ready(function () {
    g_IsOpenAjax = false; //不开启ajax 效果
    $("#btnSave").bind("click", btnSave_click);
    $("#btnCancel").bind("click", btnCancel_click);
    $("#Code").bind("input propertychange", txtCardCode_change);
    ShowVipCardTypeList();
    txtCardCode_change();
})

function ShowVipCardTypeList()
{
    //异步提交表单,表单中input元素必须设置name 属性
    $.post("/VipCard/GetVipCardLevelList", function (result) {
        var v_lis = "";
        $.each(result.data, function (i, item) {
            if (item.AID == $("#curLvel").val()) {
                v_lis += "<li class='slcw120s mr10 mb10 m10 '><span class='cf60'>" + item.Dic_Value + ":</span><span class='cf60'>" + item.Parameter2 + "<span></li>";
            }
            else {
                v_lis += "<li class='slcw120s mr10 mb10 m10'><span>" + item.Dic_Value + ":</span><span>" + item.Parameter2 + "<span></li>";
            }
        })
        $("#vipLevelList").html(v_lis);
    }, "json");
}

//自动获取卡号用户信息
function txtCardCode_change() {
    $("#balance").html("");
    $("#realName").html("");

    v_cardCode = $("#Code").val();

    $.post("/VipCard/GetCardInfo", { code: v_cardCode }, function (result) {
        if (result.code == "OK") {
            $("#balance").html("￥" + result.data.Balance);
            $("#realName").html(result.data.RealName);
            $("#recharge").html(result.data.Recharge);
            $("#curLvel").val(result.data.AID);
        }
    }, "json");
}

function btnSave_click() {

    var v_code = $("#Code").val();
    if (v_code == "") {
        alert("请输入卡号");
        return;
    }
    var v_money = $("#money").val();
    if (v_money == "") {
        alert("请输入充值金额");
        return;
    }    

    //异步提交表单,表单中input元素必须设置name 属性
    $.post("/VipCard/Recharge", { code: v_code, money: v_money }, function (result) {
        if (result.code == "OK") {
            alert(result.msg);
            window.location.href = "/VipCard/Index";      
        }
        else {
            alert(result.msg);
        }
    },"json");
}

function btnCancel_click() {
    window.history.go(-1);
}